package org.eenie.kdassistant.net;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;

import com.alibaba.fastjson.JSON;
import com.baidu.location.LocationClient;
import com.blankj.utilcode.util.PhoneUtils;

import org.eenie.kdassistant.App;
import org.eenie.kdassistant.net.yd_api.YDUserInfo;

/**
 * Created by Eenie on 2017/8/15.
 * Email: eeniework@gmail.com
 * Des: 参数模拟
 */

public class ParamsAnalog {

    //    private static ParamsAnalog sParamsAnalog;
    private String xz_uuid;
    private String zzt_token;
    private String zzt_opendid;
    private String zzt_empCode;
    private String kdy_sessionId;
    private String device_imei;
    private double device_lng = 0D;
    private double device_lat = 0D;
    private Context mContext;
    private String spf_name = "params_analog";
    private SharedPreferences spf;

    private String phoneModel;

    private String phoneBrand;

    private String zzt_uuid;


    private String yd_devsn;
    private String yd_token;
    private String yd_public_key;


    private YDUserInfo mYDUserInfo;

    private LocationClient mLocationClient;



    public ParamsAnalog(App context) {
        mContext = context;
        spf = context.getSharedPreferences("params_analog", Context.MODE_PRIVATE);






        mLocationClient = context.getApplicationComponent().getLocationClient();

//        mLocationClient.registerLocationListener(this);
//        onReceiveLocation(mLocationClient.getLastKnownLocation());

        mLocationClient.start();

//        xz_uuid = spf.getString("xz_uuid", "9a731d60d9fe44d386711bc99ced4ef6");
//        zzt_token = spf.getString("zzt_token", "toRbQYF4EeeN4ABQVq0i0A9wEr6qK9VfCSYVtX-VgEMw");
//        zzt_opendid = spf.getString("zzt_opendid", "5YXpzqIpWhOdDn8ipUKBkg");
//        kdy_sessionId = spf.getString("kdy_sessionId", "96c9e144a324ddf092d4e7701f4a760f");
//        device_imei = spf.getString("device_imei", "860162035890117");
//        zzt_empCode = spf.getString("zzt_empCode", "02179.008");


        xz_uuid = spf.getString("xz_uuid", "");
        zzt_token = spf.getString("zzt_token", "");
        zzt_opendid = spf.getString("zzt_opendid", "");
        kdy_sessionId = spf.getString("kdy_sessionId", "");
        device_imei = spf.getString("device_imei", "");
        zzt_empCode = spf.getString("zzt_empCode", "");
        zzt_uuid = spf.getString("zzt_uuid", "");
        yd_devsn = spf.getString("yd_devsn", "");
        yd_token = spf.getString("yd_token", "");
        yd_public_key = spf.getString("yd_public_key", "");

        mYDUserInfo = JSON.parseObject(spf.getString("yd_user", ""), YDUserInfo.class);


    }


//    public static void register(Context context) {
//        mContext = context;
//    }


//    public static ParamsAnalog Instance() {
//        if (sParamsAnalog == null) {
//            synchronized (ParamsAnalog.class) {
//                if (sParamsAnalog == null) {
//                    sParamsAnalog = new ParamsAnalog(mContext);
//                }
//            }
//        }
//        return sParamsAnalog;
//    }


    public String getXz_uuid() {
        return xz_uuid;
    }

    public void setXz_uuid(String xz_uuid) {
        this.xz_uuid = xz_uuid;
        saveValue("xz_uuid", xz_uuid);
    }

    public String getZzt_token() {
        return zzt_token;
    }

    public void setZzt_token(String zzt_token) {
        this.zzt_token = zzt_token;
        saveValue("zzt_token", zzt_token);
    }

    public String getZzt_opendid() {
        return zzt_opendid;
    }

    public void setZzt_opendid(String zzt_opendid) {
        this.zzt_opendid = zzt_opendid;
        saveValue("zzt_opendid", zzt_opendid);
    }

    public String getKdy_sessionId() {
        return kdy_sessionId;
    }

    public void setKdy_sessionId(String kdy_sessionId) {
        this.kdy_sessionId = kdy_sessionId;
        saveValue("kdy_sessionId", kdy_sessionId);
    }

    public String getDevice_imei() {
        return PhoneUtils.getIMEI();
    }

    public void setDevice_imei(String device_imei) {
        this.device_imei = device_imei;
        saveValue("device_imei", device_imei);
    }

    public double getDevice_lng() {

        return mLocationClient.getLastKnownLocation() == null ? 0D : mLocationClient.getLastKnownLocation().getLongitude();
    }

    public void setDevice_lng(double device_lng) {
        this.device_lng = device_lng;
    }

    public double getDevice_lat() {


        return mLocationClient.getLastKnownLocation() == null ? 0D : mLocationClient.getLastKnownLocation().getLatitude();
    }

    public void setDevice_lat(double device_lat) {
        this.device_lat = device_lat;
    }

    private void saveValue(String key, String value) {
        spf.edit().putString(key, value).apply();
    }

    private String getValue(String key) {
        return spf.getString(key, "");
    }


    public String getZzt_empCode() {
        return zzt_empCode;
    }

    public void setZzt_empCode(String zzt_empCode) {
        this.zzt_empCode = zzt_empCode;
        saveValue("zzt_empCode", zzt_empCode);
    }


    public String getYd_devsn() {
        return yd_devsn;
    }

    public void setYd_devsn(String yd_devsn) {
        this.yd_devsn = yd_devsn;
        saveValue("yd_devsn", yd_devsn);
    }


    public String getYd_token() {
        return yd_token;
    }

    public void setYd_token(String yd_token) {
        this.yd_token = yd_token;
        saveValue("yd_token", yd_token);
    }

    public String getYd_public_key() {
        return yd_public_key;
    }

    public void setYd_public_key(String yd_public_key) {
        this.yd_public_key = yd_public_key;
        saveValue("yd_public_key", yd_public_key);
    }


    public YDUserInfo getYDUserInfo() {
        return mYDUserInfo;
    }

    public void setYDUserInfo(String user) {
        mYDUserInfo = JSON.parseObject(user, YDUserInfo.class);
        saveValue("yd_user", user);
    }

    public String getPhoneModel() {
        Build build = new Build();
        return build.MODEL;
    }


    public void setPhoneModel(String phoneModel) {
        this.phoneModel = phoneModel;
    }

    public String getPhoneBrand() {
        Build build = new Build();
        return build.BRAND;
    }

    public void setPhoneBrand(String phoneBrand) {
        this.phoneBrand = phoneBrand;

    }


    public String getZzt_uuid() {
        return zzt_uuid;
    }

    public void setZzt_uuid(String zzt_uuid) {
        this.zzt_uuid = zzt_uuid;
        saveValue("zzt_uuid", zzt_uuid);
    }

//    @Override
//    public void onReceiveLocation(BDLocation location) {
//
//
////        LogUtil.json(location);
//
//        if (location != null) {
//            if (location.getLocType() == 62 || location.getLocType() == 161 || location.getLocType() == 66) {
//                this.device_lat = location.getLatitude();
//                this.device_lng = location.getLongitude();
//
//            }
//        }





//    }
//
//    @Override
//    public void onConnectHotSpotMessage(String s, int i) {
//
//        LogUtil.e(s + "  " + i);
//    }
}
